package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BizSalesExecution;
import com.ruoyi.system.service.IBizSalesExecutionService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 销售执行记录Controller
 * 
 * @author ruoyi
 * @date 2025-06-18
 */
@Controller
@RequestMapping("/system/execution")
public class BizSalesExecutionController extends BaseController
{
    private String prefix = "system/execution";

    @Autowired
    private IBizSalesExecutionService bizSalesExecutionService;

    @RequiresPermissions("system:execution:view")
    @GetMapping()
    public String execution()
    {
        return prefix + "/execution";
    }

    /**
     * 查询销售执行记录列表
     */
    @RequiresPermissions("system:execution:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BizSalesExecution bizSalesExecution)
    {
        startPage();
        List<BizSalesExecution> list = bizSalesExecutionService.selectBizSalesExecutionList(bizSalesExecution);
        return getDataTable(list);
    }

    /**
     * 导出销售执行记录列表
     */
    @RequiresPermissions("system:execution:export")
    @Log(title = "销售执行记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BizSalesExecution bizSalesExecution)
    {
        List<BizSalesExecution> list = bizSalesExecutionService.selectBizSalesExecutionList(bizSalesExecution);
        ExcelUtil<BizSalesExecution> util = new ExcelUtil<BizSalesExecution>(BizSalesExecution.class);
        return util.exportExcel(list, "销售执行记录数据");
    }

    /**
     * 新增销售执行记录
     */
    @RequiresPermissions("system:execution:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存销售执行记录
     */
    @RequiresPermissions("system:execution:add")
    @Log(title = "销售执行记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BizSalesExecution bizSalesExecution)
    {
        return toAjax(bizSalesExecutionService.insertBizSalesExecution(bizSalesExecution));
    }

    /**
     * 修改销售执行记录
     */
    @RequiresPermissions("system:execution:edit")
    @GetMapping("/edit/{executionId}")
    public String edit(@PathVariable("executionId") Long executionId, ModelMap mmap)
    {
        BizSalesExecution bizSalesExecution = bizSalesExecutionService.selectBizSalesExecutionByExecutionId(executionId);
        mmap.put("bizSalesExecution", bizSalesExecution);
        return prefix + "/edit";
    }

    /**
     * 修改保存销售执行记录
     */
    @RequiresPermissions("system:execution:edit")
    @Log(title = "销售执行记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BizSalesExecution bizSalesExecution)
    {
        return toAjax(bizSalesExecutionService.updateBizSalesExecution(bizSalesExecution));
    }

    /**
     * 删除销售执行记录
     */
    @RequiresPermissions("system:execution:remove")
    @Log(title = "销售执行记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bizSalesExecutionService.deleteBizSalesExecutionByExecutionIds(ids));
    }
}
